﻿package core.ui.controls
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;

    public class SelectItem extends Sprite
    {
        var selected:Boolean;
        var index:int = 0;
        var bg:Sprite;
        var title:TextField;
        var icon:Bitmap;

        public function SelectItem(param1:String, param2:String, param3:int, param4:BitmapData = null)
        {
            this.name = param2;
            var _loc_5:* = new Matrix();
            _loc_5.createGradientBox(198, 20, 90 / (180 / Math.PI), 0, 0);
            this.bg = new Sprite();
            this.bg.graphics.beginGradientFill("linear", [3449586, 34534], [1, 1], [0, 255], _loc_5);
            this.bg.graphics.drawRect(0, 0, param3 - 2, 20);
            this.bg.graphics.endFill();
            this.bg.alpha = 0;
            addChild(this.bg);
            if (param4 != null)
            {
                this.icon = new Bitmap(param4);
                this.icon.x = 3;
                this.icon.y = 2;
                addChild(this.icon);
            }
            this.title = new TextField();
            this.title.defaultTextFormat = new TextFormat("Arial, Helvetica, San-serif", AppState.TextSize, 0, false, false, false, null, null, "left");
            this.title.multiline = false;
            this.title.selectable = false;
            this.title.autoSize = TextFieldAutoSize.LEFT;
            this.title.height = 16;
            this.title.text = param1;
            this.title.x = this.icon != null ? (22) : (2);
            this.title.y = 2;
            addChild(this.title);
            this.addEventListener(MouseEvent.ROLL_OVER, this.MouseOver, false, 1, true);
            this.addEventListener(MouseEvent.ROLL_OUT, this.MouseOut, false, 1, true);
            return;
        }// end function

        public function get text() : String
        {
            return this.title.text;
        }// end function

        public function set text(selectable:String) : void
        {
            this.title.text = selectable;
            return;
        }// end function

        public function Select(param1:Boolean = true)
        {
            this.selected = param1;
            if (param1)
            {
                this.bg.alpha = 1;
                this.title.textColor = 16777215;
            }
            else
            {
                this.bg.alpha = 0;
                this.title.textColor = 0;
            }
            return;
        }// end function

        private function MouseOver(event:MouseEvent) : void
        {
            if (!this.selected)
            {
                this.bg.alpha = 0.9;
                this.title.textColor = 16777215;
            }
            return;
        }// end function

        private function MouseOut(event:MouseEvent) : void
        {
            if (!this.selected)
            {
                this.bg.alpha = 0;
                this.title.textColor = 0;
            }
            return;
        }// end function

    }
}
